package ru.susu.algebra.jtex.formula;

import ru.susu.algebra.jtex.StringTexElement;
import ru.susu.algebra.jtex.TexElementBase;
import ru.susu.algebra.jtex.utils.TexUtils;

/**
 * @author akargapolov
 * @since: 23.08.2010
 */
public class FormulaTexElement extends TexElementBase
{
	private boolean _centered = false;

	@Override
	public String generateContent()
	{
		StringBuffer buffer = new StringBuffer();
		buffer.append(_centered ? "$$" : "$").append(generateSubItemsContent()).append(_centered ? "$$" : "$");
		return buffer.toString();
	}

	public FormulaTexElement setCentered()
	{
		_centered = true;
		return this;
	}

	public static FormulaTexElement formula()
	{
		return new FormulaTexElement();
	}

	public static FormulaTexElement formula(String text)
	{
		return (FormulaTexElement)new FormulaTexElement().addSubElement(StringTexElement.text(text));
	}

	public static FormulaTexElement centeredFormula()
	{
		return formula().setCentered();
	}

	public static String frac(String numerator, String denominator)
	{
		return "\\frac{" + numerator + "}{" + denominator + "}";
	}

	private static final String SUM = "\\sum";

	public static String sum(Object from, Object to)
	{
		return SUM + TexUtils.index(from) + TexUtils.pow(to);
	}

	public static String brackets(Object formula)
	{
		return MathSymbols.LEFT + MathSymbols.LEFT_BRACKET + formula + MathSymbols.RIGHT + MathSymbols.RIGHT_BRACKET;
	}

	public static String text(Object text)
	{
		return TEXT + "{" + text + "}";
	}

	public static String sqrt(Object value)
	{
		return "\\sqrt{" + value + "}";
	}

	public static String in(Object value)
	{
		return MathSymbols.IN + "{" + value + "}";
	}

	public static String pmod(Object value)
	{
		return MathSymbols.PMOD + "{" + value + "}";
	}

	public static final String VAREPSILON = "\\varepsilon";
	public static final String IN = "\\in";
	public static final String DEG = "\\deg";
	public static final String CDOT = "\\cdot";
	public static final String LANGLE = "\\langle"; //<
	public static final String RANGLE = "\\rangle"; //>
	public static final String TIMES = "\\times"; //умножение
	private static final String TEXT = "\\text"; //текст



}
